package com.czf.company.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.czf.common.entity.CreditCompany;
import com.czf.common.mapper.CreditCompanyMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zfChen
 * @create 2022/4/24 17:20
 */
@Service
public class CreditCompanyServiceImpl {

    @Autowired
    private CreditCompanyMapper creditCompanyMapper;

    public int register(CreditCompany creditCompany) {
        int insert = creditCompanyMapper.insert(creditCompany);
        return insert;
    }

    public Long login(String account, String password) {
        QueryWrapper<CreditCompany> wrapper = new QueryWrapper<>();
        wrapper.eq("account",account);
        wrapper.eq("password",password);
        CreditCompany creditCompany = creditCompanyMapper.selectOne(wrapper);
        if (ObjectUtils.isNotEmpty(creditCompany)) {
            return creditCompany.getUserId();
        }
        return null;
    }

    public CreditCompany select(Long userId) {
        CreditCompany creditCompany = creditCompanyMapper.selectById(userId);
        if (ObjectUtils.isNotEmpty(creditCompany)) {
            return creditCompany;
        }
        return null;
    }
}
